import Vue from 'vue';
// 手机号脱敏处理(180****3976)
Vue.filter('mobileDesensitize', function(phone) {
  const pat = /(\d{3})\d*(\d{4})/;
  const result = phone.replace(pat, '$1***$2');
  return result;
});
// 姓名脱敏处理(3个字以内脱敏第一个字，4—6个字脱敏前两个字，大于6个字脱敏第3—6个字)
Vue.filter('nameDesensitize', function(name) {
  let userName = '';
  if (name.length === 2) {
    userName = name.substring(0, 1) + '*';
  } else if (name.length === 3) {
    userName = name.substring(0, 1) + '*' + name.substring(2, 3);
  } else if (name.length > 3) {
    userName = name.substring(0, 1) + '*' + '*' + name.substring(3, name.length);
  }
  return userName;
});
// 身份证号脱敏
Vue.filter('idDesensitize', function(dateStr) {
  let idNo = dateStr.substring(0, 3);
  for (let i = 0; i < dateStr.length - 6; i++) {
    idNo = idNo + '*';
  }
  idNo = idNo + dateStr.substring(dateStr.length - 3);
  return idNo;
});
// 银行卡号脱敏处理
Vue.filter('bankCardDesensitize', function(dateStr) {
  let carNumber = dateStr.substring(0, 4);
  for (let i = 0; i < dateStr.length - 8; i++) {
    carNumber = carNumber + '*';
  }
  carNumber = carNumber + dateStr.substring(dateStr.length - 4);
  return carNumber;
});
